package com.moyun.finance.controller;

import com.moyun.finance.entity.Contract;
import com.moyun.finance.entity.Response;
import com.moyun.finance.service.ContractService;
import com.moyun.finance.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/contract")
public class ContractController {
    @Autowired
    ContractService cs;

    //合同新增
    @RequestMapping("/save")
    public @ResponseBody Response save(@RequestBody Contract contract){
        Response res = cs.save(contract);
        return res;
    }

    //合同修改
    @RequestMapping("/update")
    public @ResponseBody Response update(@RequestBody Contract contract){
        Response res = cs.update(contract);
        return res;
    }

    //合同删除
    @RequestMapping("/delete")
    public @ResponseBody Response delete(@RequestBody Contract contract){
        Response res = cs.delete(contract);
        return res;
    }

    //查询指定公司所有合同
    @RequestMapping("/findAllByCompanyId")
    public @ResponseBody Response findAllByCompanyId(String companyId){
        List<Contract> contracts = cs.findAll(companyId);
        return new Response("",contracts,true);
    }

    //根据id查合同
    @RequestMapping("/findById")
    public @ResponseBody Response findOneById(String contractId){
        Contract c = cs.findOneById(contractId);
        return new Response("",c,true);
    }

    //删除产品合同关联记录
    @RequestMapping("/deleteProduct")
    public @ResponseBody Response deleteProduct(List<String> pcmIds){
        Response res = cs.deleteProduct(pcmIds);
        return res;
    }

    //根据类型查本公司下所有
    @RequestMapping("/findByType")
    public @ResponseBody Response findByType(String companyId, int type){
        List<Contract> contracts = cs.findByType(companyId, type);
        return new Response("",contracts,true);
    }

    //根据子菜单查本公司下所有
    @RequestMapping("/findByAllType")
    public @ResponseBody Response findByTypeAndAllType(String companyId, int type, String allTypeId){
        List<Contract> contracts = cs.findByTypeAndAllType(companyId, type, allTypeId);
        return new Response("",contracts,true);
    }
}
